<?php

namespace app\api\server\music;

use app\api\model\music\MusicDjTeachingApiModel;
use app\api\ServerBase;
use app\admin\validate\music\MusicDjTeachingValidate;
use app\logic\model\music\MusicLogicModel;
use app\logic\model\user\UserLogicModel;
use app\logic\single\GoodsSingle;
use think\db\exception\DbException;
use think\Request;

class MusicDjTeachingServer extends ServerBase
{
    protected $model;
    protected $request;
    /**
     * @var mixed
     */
    protected $param;
    /**
     * @var mixed
     */
    protected $validate;

    function __construct(Request $request)
    {
        $this->request = $request;
        $this->param = $request->param();
        $this->model = new MusicDjTeachingApiModel();
        $this->validate = new MusicDjTeachingValidate();
    }

    function getList()
    {
        [$page, $limit] = $this->getPage($this->param);
        $field='id,title,music_id,img,price,original_price';
        [$list, $count] = $this->model->getApiList($this->param, [], $field, $page, $limit);
        $result['data'] = $list;
        $result['count'] = $count;
        $this->getMessageCode('adminMessage.success.select', 2);
        return $result;
    }

    function getDetail()
    {
        $id =  $this->request->param('id');
        $info = $this->model->details($id,'id,title,music_id,img,price,original_price,content,sale');
        if(empty($info)){
            $this->getMessageCode('code_common.not_find',1);
            return false;
        }
        $info['is_have'] = GoodsSingle::getInstance()->isHave($info['id'],30,$this->request->user_id);
        $this->getMessageCode('adminMessage.success.select', 2);
        return $info;
    }
}